<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细管理</title>
<#include "../common/link.ftl"/>
    <script>
        $(function () {
            //编辑页面的数据回显
            $(".btn-input").click(function () {

                //清空表单中的数据
                $("#editForm input").val("");
//                $("#editForm").get(0).reset();
                //获取当前按钮上绑定的数据
                var json = $(this).data("json");
                if (json) {
                    //填充到表单中
                    $("input[name=id]").val(json.id);
                    $("input[name=title]").val(json.title);
                    $("input[name=sequence]").val(json.sequence);

                    //目录的信息
                    //$("input[name=parentId]").val(json.parentId);
                    //$("input[name=parentTitle]").val(json.parentTitle);
                }
                $("input[name='parent.id']").val(${(dic.id)!});
                $("input[name=parentTitle]").val('${(dic.title)!}');

                $("#editModal").modal("show");
            })

            //提交表单
            $(".btn-submit").click(function () {
                //data:后台响应回来的数据: {success:true,errorMsg:""}
                $("#editForm").ajaxSubmit(function (data) {
                    handleMessage(data);
                })
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
<#include "../common/navbar.ftl"/>
    <!--菜单回显-->
<#assign currentMenu="systemDictionaryItem"/>
<#include "../common/menu.ftl"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典目录管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <input type="hidden" name="parentId" value="${(qo.parentId)!}">
                </form>
                <br/>
                <div class="row">
                    <div class="  col-sm-3">
                        <div class="panel panel-info">
                            <div class="panel-heading"><strong>字典明细</strong></div>
                            <ul class="list-group" id="dicDirUl">
                            <#list dics as d>
                                <li class="list-group-item">
                                    <a class="dicDir" href="/systemDictionaryItem/list?parentId=${d.id}">${d.title}</a>
                                </li>
                            </#list>
                                <script>
                                    $(".dicDir[data-pid='-1']").closest("li").addClass("active");
                                    $(".dicDir[data-pid='-1']").css("color", "white")
                                </script>
                            </ul>
                        </div>
                    </div>
                    <div class="col-sm-9">
                    <#if pageInfo??>
                        <a href="javascript:;" class="btn btn-success btn-input" style="margin: 10px">
                            <span class="glyphicon glyphicon-plus"></span> 添加明细
                        </a>
                        <!--编写内容-->
                    <div class="box-body table-responsive no-padding ">
                        <table class="table table-hover table-bordered">
                            <tr>
                                <th>编号</th>
                                <th>标题</th>
                                <th>序号</th>
                                <th>操作</th>
                            </tr>
                            <#list pageInfo.list as entity>
                                <tr>
                                    <td>${entity_index + 1}</td>
                                    <td>${entity.title}</td>
                                    <td>${entity.sequence}</td>
                                    <td>
                                        <a class="btn btn-info btn-xs btn-input" href="javascript:;"
                                           data-json='${entity.json}'>
                                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                                        </a>
                                        <a href="javascript:;"
                                           data-url="/systemDictionaryItem/delete?id=${entity.id}"
                                           class="btn btn-danger btn-xs btn-delete">
                                            <span class="glyphicon glyphicon-trash"></span> 删除
                                        </a>
                                    </td>
                                </tr>
                            </#list>
                        </table>
                        <!--分页-->
                        <#include "../common/page.ftl"/>
                    </#if>
                    </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
<#include "../common/footer.ftl"/>
</div>
<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">字典明细编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate" method="post"
                      id="editForm">
                <#--如果取到的值为null或者没有,此时freemarker会报错-->
                    <input type="hidden" name="id" >
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="title" class="col-sm-2 control-label">字典目录：</label>
                        <div class="col-sm-4">
                            <input type="hidden" name="parent.id">
                            <input type="text" class="form-control" name="parentTitle" disabled style="width: 300px">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="title" class="col-sm-2 control-label">标题：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="title" name="title"
                                   placeholder="请输入标题" style="width: 300px">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sequence" class="col-sm-2 control-label">序号：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="sequence" name="sequence"
                                   placeholder="请输入编码" style="width: 300px">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">戳这关闭</button>
                <button type="button" class="btn btn-primary btn-submit">朕要提交</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
